package org.bing.engine.common.remoting.hessian;

import java.net.MalformedURLException;
import java.net.URL;

import org.bing.engine.common.remoting.RemotingInvoker;
import org.bing.engine.common.remoting.RemotingProxyFactory;

public class HessianProxyFactory implements RemotingProxyFactory {
    private static final org.bing.adapter.com.caucho.hessian.client.HessianProxyFactory factory = new org.bing.adapter.com.caucho.hessian.client.HessianProxyFactory();

    @SuppressWarnings("unchecked")
    public <T> T create(Class<T> api, String url) {
        String newUrl = url + api.getName();
        try {
            return (T) factory.create(api, newUrl);
        } catch (MalformedURLException e) {
            throw new RuntimeException("Can't create hessian proxy!", e);
        }
    }

    public RemotingInvoker createInvoker(String clz, String url) {
        try {
            String newUrl = url + clz;
            return new HessianInvoker(new URL(newUrl), clz);
        } catch (MalformedURLException e) {
            throw new RuntimeException("Can't create hessian invoker!", e);
        }
    }
}